package com.khalil.kkadmin.web;

import com.khalil.kkadmin.common.web.RespResult;
import com.khalil.kkadmin.system.user.SysUserManager;
import com.khalil.kkadmin.system.user.vo.SysUserEditVO;
import com.khalil.kkadmin.system.user.vo.SysUserVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("userMgmt")
public class UserMgmtController {

    private final SysUserManager sysUserManager;

    public UserMgmtController(SysUserManager sysUserManager) {
        this.sysUserManager = sysUserManager;
    }


    @GetMapping("list")
    public RespResult<List<SysUserVO>> list() {
        List<SysUserVO> sysUserVOList = sysUserManager.list();
        return RespResult.ok(sysUserVOList);
    }

    @PostMapping("")
    public RespResult<SysUserEditVO> add(@RequestBody SysUserEditVO sysUserVO) {
        SysUserEditVO userVO = sysUserManager.createUser(sysUserVO);
        return RespResult.ok(userVO);
    }

    @PutMapping("")
    public RespResult<SysUserEditVO> edit(@RequestBody SysUserEditVO sysUserVO) {
        SysUserEditVO updatedUser = sysUserManager.updateUser(sysUserVO);
        return RespResult.ok(updatedUser);
    }

    @DeleteMapping("/{id}")
    public RespResult<Void> delete(@PathVariable Long id) {
        sysUserManager.deleteUser(id);
        return RespResult.ok(null);
    }
}
